<template>
	<div class="news">
		<div class="table" v-show="parentDetailData.isTabelShow">
			<div class="container">
				<div class="handle-box">
					<div class="handle-box" style="float: left">
						<!--<el-input v-model="searchcondition.title" placeholder="标题" class="handle-input mr10"></el-input>
						<el-button type="primary" icon="search" @click="search">搜索</el-button>-->
					</div>
					<div style="float: right; padding-bottom: 10px;">
						<el-button type="primary" v-if="my_user_info.userType=='user_admin'" @click="handleDetail(null,null)" icon="add">添加</el-button>
					</div>
				</div>
				<el-table stripe :data="data" border style="width: 100%" ref="multipleTable" v-loading="loading">
					<el-table-column prop="investorName" label="投资人"></el-table-column>
					<el-table-column prop="companyName" label="融资机构"></el-table-column>
					<el-table-column prop="investPrice" label="融资额度"></el-table-column>
					<el-table-column prop="investTagCN" label="融资轮次"></el-table-column>
					<el-table-column prop="investTime" label="融资日期"></el-table-column>
					<el-table-column label="操作" width="200">
						<template slot-scope="scope">
							<el-button size="small" type="primary" @click="handleDetail(scope.$index, scope.row)">编辑</el-button>
							<el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</div>
		<detail ref="detail" :proId='searchcondition.productId' :id="id" :parentDetailData="parentDetailData" v-on:close="handleClose"></detail>
	</div>
</template>

<script>
	import Vue from 'vue';
	import $ from 'jquery';
	import service from '../../../js/services/projectinvestservice.js';
	import detail from './detail';
	let img = require('@/assets/nodata.jpg');

	window.changeImg = function(e) {
		$(e.target).attr('src', img);
	}
	export default {
		components: {
			detail
		},
		data() {
			return {
				tableData: [],
				searchcondition: {
					pageNum: 1,
					pageSize: 100,
					productId: 0
				},
				total: 0,
				priDialogFormVisible: false,
				id: 0,
				parentDetailData: {
					isTabelShow: true
				},
				loading: true,
				categories: [],
				img: img,
				my_user_info: JSON.parse(sessionStorage.getItem('my_user_info'))
			}
		},
		mounted() {
			this.searchcondition.productId = this.$route.query.id;
			service.getPageData(this);
		},
		computed: {
			data() {
				return this.tableData;
			}
		},
		methods: {
			search() {
				this.searchcondition.pageNum = 1;
				service.getPageData(this);
			},
			handleCurrentChange(val) { //翻页
				this.searchcondition.pageNum = val;
				service.getPageData(this);
			},
			handleSizeChange(val) { //每页数量
				this.searchcondition.PageSize = val;
				service.getPageData(this);
			},
			handleDetail(index, row) {
				service.showDetail(this, row);

			},
			checkComments(index, row) {
				let self = this;
				if(row != null && index != null) {
					this.id = row.id;
				} else {
					this.id = null;
				}
				self.$router.push({
					path: '/comments',
					query: {
						id: row.id
					}
				});
			},
			handleClose() {
				service.getPageData(this);
			},
			handleDelete(index, row) {
				service.handleDelete(this, row.id);
			},
			handleSetArticleStatus(state, index, row) {
				let self = this;
				self.$confirm('确定要' + (state == 0 ? "发布" : "取消发布") + ', 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					state: 'warning'
				}).then(() => {
					let params = {};
					params.id = row.id;
					console.log(params);

					if(row.articleStatus == 1) {
						params.articleStatus = 0;
					} else {
						params.articleStatus = 1;
					}
					self.httptool.ajaxPost(self.apis.publicArticle, params, function(res) {
						if(res.code == 1) {
							service.getPageData(self);
						}
					});
				}).catch(() => {

				});
			},

		}
	}
</script>

<style lang="less" scoped="scoped">
	.handle-box {
		margin-bottom: 20px;
	}
</style>